#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

void create_fork(int level){
    if(level > 10){
        exit(0);
    }
    printf("Level %2d: PID=%d, PPID=%d\n", level,  getpid(), getppid());

    pid_t pid = fork();

    if(pid < 0){
        perror("fork failed");
        exit(1);
    }
    else if(pid == 0){
        sleep(10);
        create_fork(level+1);
    }
    else{
        wait(NULL);
        exit(0);
    }
}

int main(){
    create_fork(1);
    return 0;
}
